Skip to content

Add BaggageLogProcessor to opentelemetry-processor-baggage#4371

Open
Manvi2402 wants to merge 7 commits intoopen-telemetry:mainfrom
Manvi2402:add-baggage-log-processor
Open

Add BaggageLogProcessor to opentelemetry-processor-baggage#4371
Manvi2402 wants to merge 7 commits intoopen-telemetry:mainfrom
Manvi2402:add-baggage-log-processor

Conversation

@Manvi2402
Copy link
Copy Markdown

Description

Adds BaggageLogProcessor which reads entries stored in Baggage from the current context and adds the baggage entries' keys and values to the log record as attributes on emit.

This is analogous to the existing BaggageSpanProcessor but for logs.

Fixes #4062

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • [ x ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ x ] This change requires a documentation update

How Has This Been Tested?

Added unit tests in test_baggage_log_processor.py:

  • test_check_the_baggage - verifies BaggageLogProcessor is instance of LogRecordProcessor
  • test_baggage_added_to_log_record - verifies baggage is added to log attributes
  • test_baggage_with_prefix - verifies predicate filtering with string prefix
  • test_baggage_with_regex - verifies predicate filtering with regex
  • test_no_baggage_not_added - verifies no baggage keys added when baggage is empty

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • [ x ] No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • [ x] Followed the style guidelines of this project
  • [ x] Changelogs have been updated
  • [ x] Unit tests have been added
  • [ x] Documentation has been updated

@tammy-baylis-swi
Copy link
Copy Markdown
Contributor

Thanks @Manvi2402 for submitting. I think this is a nice analog feature and iiuc shouldn't interfere with the Logging API stabilization efforts. I've left some comments.

Please could you also:

  • tox -e precommit
  • tox -e lint-processor-baggage

@tammy-baylis-swi tammy-baylis-swi moved this to Reviewed PRs that need fixes in Python PR digest Mar 30, 2026
@tammy-baylis-swi tammy-baylis-swi requested a review from a team March 30, 2026 17:47
@Manvi2402 Manvi2402 force-pushed the add-baggage-log-processor branch from 176f8d3 to 3449a3d Compare March 31, 2026 03:17
@Manvi2402
Copy link
Copy Markdown
Author

Thanks for the review @tammy-baylis-swi . I've addressed all the comments in the latest commit 3449a3d

Added collision handling to avoid overwriting existing log record attributes.
Added max_baggage_attributes parameter to limit number of baggage attributes added.
Added support for multiple predicates via a sequence of predicates.

def __init__(
self,
baggage_key_predicate: BaggageKeyPredicatesT,
max_baggage_attributes: Optional[int] = None,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec outlines 128 as a max for attributes though not specific to baggage. Maybe we could use this as a default?

@tammy-baylis-swi tammy-baylis-swi requested a review from a team March 31, 2026 17:01
…s=128, multiple predicates test and README example
@Manvi2402
Copy link
Copy Markdown
Author

Thanks for the follow-up @tammy-baylis-swi I've addressed all the comments in the latest commit:

Added docstring to on_emit documenting collision handling behavior
Changed max_baggage_attributes default to 128 as per the spec
Added test_multiple_predicates test case
Updated README with multiple predicates example
Fixed CHANGELOG to link PR #4371 instead of issue

@tammy-baylis-swi
Copy link
Copy Markdown
Contributor

Hi @Manvi2402 please add a bit more test coverage for configurable max_baggage_attributes then run these again:

  • tox -e precommit
  • tox -e lint-processor-baggage

@Manvi2402
Copy link
Copy Markdown
Author

Hi @tammy-baylis-swi , I've added the test for max_baggage_attributes. I tried running tox -e precommit and tox -e lint-processor-baggage locally but they fail on Windows because sh command is not available.

@tammy-baylis-swi
Copy link
Copy Markdown
Contributor

Hi @tammy-baylis-swi , I've added the test for max_baggage_attributes. I tried running tox -e precommit and tox -e lint-processor-baggage locally but they fail on Windows because sh command is not available.

Thanks @Manvi2402 !

I'm not a Windows user myself but I think those tox commands should work if you use git bash or WSL. Could you give one of those a try?

@Manvi2402
Copy link
Copy Markdown
Author

Hi @tammy-baylis-swi , I ran tox -e precommit and it passed after ruff auto-fixed some formatting. I also fixed the pylint issues in log_processor.py (naming convention and staticmethod). The only remaining pylint warning is ALLOW_ALL_BAGGAGE_KEYS in the existing processor.py which was there before my changes.

Copy link
Copy Markdown
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me. Thank you @Manvi2402.


def __init__(
self,
baggage_key_predicate: BaggageKeyPredicate,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you've used a Union here. The BaggageSpanProcessor just takes a single predicate, would you mind updating it to match this so they are kept consistent? Updating to use the union should be fully backward compatible so long as we use the if callable check like you have below.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @MikeGoldsmith , I've updated BaggageSpanProcessor to support multiple predicates using the same Union type, with the if callable check for backward compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

Add baggage attributes to log records

3 participants